//
//  WineListCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/6.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "WineListCell.h"
#import "OneGoodsModel.h"
@interface WineListCell ()

@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *markLabel;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activity;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightLabel;
@property (weak, nonatomic) IBOutlet UILabel *twoPriceLabel;

@end

@implementation WineListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.goodsNameLabel.font = MYFONT(15);
    self.priceLabel.font = MYFONT(17);
    self.twoPriceLabel.font = MYFONT(14);
    self.rightLabel.font = MYFONT(14);
    self.priceLabel.textColor = [UIColor redColor];
    self.markLabel.font = MYFONT(10);
    self.markLabel.textAlignment = NSTextAlignmentCenter;
    self.markLabel.textColor = [UIColor redColor];
    self.markLabel.layer.cornerRadius = 5;
    self.markLabel.layer.masksToBounds = YES;
    self.markLabel.backgroundColor = viewBgGrey;
    
    
    // Initialization code
}
- (void)setModel:(OneGoodsModel *)model{
    _model = model;
    
    self.goodsNameLabel.text = _model.goods_name;
    self.priceLabel.text = [NSString stringWithFormat:@"%@P",_model.goods_price];
    self.rightLabel.text = @"99%好评";
    self.twoPriceLabel.attributedText = [self attributedStrin:[NSString stringWithFormat:@"零售价:%.2f",_model.goods_price.floatValue * 0.2 + _model.goods_price.floatValue]];
    
    [self.activity startAnimating];
    
    [[SDWebImageManager sharedManager]downloadImageWithURL:[NSURL URLWithString:_model.goods_image_url] options:SDWebImageRetryFailed progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image) {
            
            self.leftImageView.image = image;
            
            [self.activity stopAnimating];
            
        }
    }];
    
//    [self.leftImageView sd_setImageWithURL: placeholderImage:nil options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        if (image) {
//
////            self.model.image = image;
//
//            [self.activity stopAnimating];
//
//        }
//    }];
    
}


- (NSMutableAttributedString *)attributedStrin:(NSString *)str{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:MYFONT(14) range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:darkGray range:NSMakeRange(0, str.length)];
     [attr addAttribute:NSStrikethroughStyleAttributeName value:@1 range:NSMakeRange(0, str.length)];
//    [attr addAttribute:NSKernAttributeName value:@(0.5f) range:NSMakeRange(0, str.length)];
    
    return attr;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
